<?php

namespace Common\Model;

/**
 * Pay.class实例模型
 * 
 * @author songanwei
 * @date 2016-1-5
 */
class PayModel extends BaseModel {

    protected $trueTableName = 'bp_pay';
    protected $field = 'id,name,creator,operator,createtime,updatetime,isdelete';

    /**
     * 返回全部数据
     * @modify trainyao 2016-05-19    创建
     */
    public function getAll() {
        $option = array(
            'isdelete' => NOT_DELETE,
        );

        return $this->where($option)->field($this->field)->select();
    }

    /**
     * 添加默认支付方式
     * @modify trainyao 2016-05-20 创建
     * @param  string   $name      支付方式名字
     * @return boolean   执行结果
     */
    public function addInfo($name) {
        $creator = getAdminId();
        $data = array(
            'name' => $name,
            'creator' => $creator,
            'operator' => $creator,
        );
        return empty($this->add($data)) ? false : true;
    }

    /**
     * 根据支付方式名字删除支付方式
     * @modify trainyao 2016-05-20 创建
     * @param  string   $name      支付方式名
     * @return boolean              执行结果
     */
    public function deleteInfoByName($name) {
        $operator = getAdminId();
        $option = array(
            'isdelete' => NOT_DELTE,
            'name' => $name,
        );

        $data = array(
            'isdelete' => IS_DELETE,
            'operator' => $operator,
        );

        return empty($this->where($option)->save($data)) ? false : true;
    }

    /**
     * 获取所有支付方式
     * @modify trainyao 2016-01-09    创建
     * @return array   支付方式信息数组
     */
    public function getInfo() {
        $option = array(
            'isdelete' => NOT_DELETE,
        );

        $data = $this->where($option)->select();
        return empty($data) ? array() : $data;
    }
}
